package com.lkinga.www.DAO;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;

import com.lkinga.www.Model.recommend;
import com.lkinga.www.Util.HadoopUtil;
import com.lkinga.www.View.MovieRateFrame;

// vv FileSystemDoubleCat
public class filesystem {

  public static void run() throws Exception {
    String uri = HadoopUtil.HDFS + "/data/output/grade/part-r-00000";
    //Configuration conf = new Configuration();
   // FileSystem fs = FileSystem.get(URI.create(uri), conf);
    int movie[] = new int[3];
    float grate[] = new float[3];
    Configuration conf = new Configuration();  
    FileSystem fs = FileSystem.get(URI.create(uri), conf);  
    FSDataInputStream hdfsInStream = fs.open(new Path(uri));  
    InputStreamReader isr = new InputStreamReader(hdfsInStream, "utf-8");  
    BufferedReader br = new BufferedReader(isr);  
    String line;  
    // int k = 0;  
    Map<Integer, Float> link = new HashMap<Integer, Float>();
    while ((line = br.readLine()) != null) {  
       String arr[]= HadoopUtil.SPARATOR.split(line); 
     
       link.put(Integer.parseInt(arr[0]), Float.valueOf(arr[1]));
       
    }
    for (Map.Entry<Integer, Float> entry : link.entrySet()) {
    	
        //System.out.println(entry.getKey()+"    "+entry.getValue());
    	float f = entry.getValue();
    	 
    	 System.out.println();
    		if(f>grate[0]) {
    			grate[0]=f;
    			movie[0]=entry.getKey();
    			continue;
    		} else if(f>grate[1]) {
    			grate[1]=f;
    			movie[1]=entry.getKey();
    			continue;
    		}else if(f>grate[2]) {
    			grate[2]=f;
    			movie[2]=entry.getKey();
    			continue;
    		}
    		
    
    }
    for(int a=0;a<3;a++) {
    	
    	System.out.println(grate[1]+"     "+movie[a]);
    }
    recommend.set(movie[0],movie[1],movie[2]);
  }
 
}

